import 'package:animation_effect_demo/src/effects/base/base_effect.dart';
import 'package:animation_effect_demo/src/effects/effect_template.dart';
import 'package:animation_effect_demo/src/effects/image_effect/image_operation.dart';
import 'package:animation_effect_demo/src/effects/text_operation.dart';
import 'package:animation_effect_demo/src/pages/edit_template_page.dart';
import 'package:animation_effect_demo/src/pages/edit_text_template_page.dart';
import 'package:animation_effect_demo/src/widget/fixed_animation_container.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:uuid/uuid.dart';

///腾讯文档地址
///https://docs.qq.com/doc/DQk5BbFlmaUpYR0Ft?u=9d4b55476fd04f98aa765d869a597fd1
///

void main() {
  runApp(const MyApp());
}

//git测试
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return OKToast(
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
            primarySwatch: Colors.blue,
            brightness: Brightness.dark,
            scaffoldBackgroundColor: Color(0xFF030b16)),
        home: const MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<EffectTemplate> dynamicTemplateList = [
    EffectTemplate(Uuid().v4(), '测试02', effectType: EffectType.effect02),
    EffectTemplate(Uuid().v4(), '测试03', effectType: EffectType.effect03),
    EffectTemplate(Uuid().v4(), '测试05', effectType: EffectType.effect05),
    EffectTemplate(Uuid().v4(), '测试07', effectType: EffectType.effect07),
    EffectTemplate(Uuid().v4(), '测试08', effectType: EffectType.effect08),
    EffectTemplate(Uuid().v4(), '测试10', effectType: EffectType.effect10),
    EffectTemplate(Uuid().v4(), '测试14', effectType: EffectType.effect14),
    EffectTemplate(Uuid().v4(), '测试15', effectType: EffectType.effect15),
    EffectTemplate(Uuid().v4(), '测试16', effectType: EffectType.effect16),
    EffectTemplate(Uuid().v4(), '测试20', effectType: EffectType.effect20),
    EffectTemplate(Uuid().v4(), '测试27', effectType: EffectType.effect27),
    EffectTemplate(Uuid().v4(), '测试30', effectType: EffectType.effect30),
    EffectTemplate(Uuid().v4(), '文本测试',
        effectType: EffectType.textEffect,
        operation: EffectOperation(
            textOperation: TextOperation(
                textStyleData: TextStyleData(
                    content: 'Hello Flutter!',
                    fontStyle: 'SongTi',
                    fontSize: 16,
                    fontName: '宋体'),
                textAttrData: TextAttrData(
                    fontColors: [Colors.red],
                    backgroundStyle: BackgroundStyle(
                        type: StyleType.color,
                        backgroundColor: Colors.transparent)),
                textEffectData: TextEffectData(
                    animationType: AnimationType.left,
                    speed: 90,
                    brightness: 100)))),
    EffectTemplate(Uuid().v4(), '静态图片',
        effectType: EffectType.staticImageEffect,
        operation: EffectOperation(
            imageOperation: ImageOperation(
                imagePaths: ['assets/images/default_2019_image_2.png'],
                width: 278,
                height: 264,
                fixType: FixType.fill)

            // imageOperation: ImageOperation(
            //     imagePaths: ['assets/images/default_2019_image_1.png'],
            //     width: 96,
            //     height: 16,
            //     fixType: FixType.contain)

        ))
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('灯效Demo'),
      ),
      body: GridView.builder(
          padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16.0),
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 3, crossAxisSpacing: 8, mainAxisSpacing: 8),
          itemCount: dynamicTemplateList.length,
          itemBuilder: (BuildContext context, int index) {
            var template = dynamicTemplateList[index];
            var baseEffect = BaseEffect(template.effectType);
            return GestureDetector(
              onTap: () {
                Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                  if (template.effectType == EffectType.textEffect) {
                    return EditTextTemplatePage(
                      operation: template.operation!,
                    );
                  } else {
                    return EditTemplatePage(
                      baseEffect: baseEffect,
                      operation: template.operation,
                    );
                  }
                }));
              },
              child: Material(
                borderRadius: BorderRadius.circular(8),
                color: Colors.grey.shade800,
                child: Padding(
                  padding: const EdgeInsets.all(2.0),
                  child: Column(
                    children: [
                      Expanded(
                        child: FixedAnimationContainer(
                          baseEffect,
                          operation: template.operation,
                        ),
                      ),
                      const SizedBox(
                        height: 2.0,
                      ),
                      Text(
                        template.name,
                        style: TextStyle(fontSize: 12.0),
                      )
                    ],
                  ),
                ),
              ),
            );
          }),
    );
  }
}
